<template>
	<view class="wrap">
		<u-form class="form" :model="model" :rules="rules" ref="uForm" label-position="left">
			<u-form-item label="直播主题" prop="theme" label-width="180" :required="true">
				<u-input v-model="model.theme" type="text" placeholder="请输入直播主题" maxlength="64" style="text-align: left;"></u-input>
			</u-form-item>
			<u-form-item label="直播类型" prop="liveType" label-width="180" :required="true">
				<js-select v-model="model.liveType" dict-type="wechat_liveType" itemLabel="dictValue"
					itemValue="dictKey" placeholder="请选择直播类型"></js-select>
			</u-form-item>
		</u-form>
		<view style="display: flex;flex-direction: row;">
			<u-button class="btn" style="width: 50%;margin-right: 10rpx;" type="primary" @click="submit">保存</u-button>
			<u-button class="btn" style="width: 50%;" @click="cancel">取消</u-button>
		</view>	
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					theme: '',
					liveType: ''
				},
				rules: {
					theme: [{
						required: true,
						message: '请输入直播主题',
						trigger: ['blur','change']
					}],
					liveType: [{
						required: true,
						message: '请选择直播类型',
						type: 'number',
						trigger: 'change'
					}]
				}
			}
		},
		create() {
			// console.log("create...");
		},
		onReady() {
			// console.log("onReady...");
			// this.$refs.uForm.setRules(this.rules);
		},
		mounted(){
			//当组件挂在popup弹出层时，上面的onReady方法执行不到，所以setRules在此处初始
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						this.$emit("onSubmitQuickLiving",this.model);
					}else {
						this.$u.toast('您填写的信息有误，请根据提示修正。');
					}
				})
			},
			cancel() {
				this.$emit("onCancelQuickLiving");
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wrap {
		padding: 30rpx;
	}
</style>